package com.atguigu.cloud.controller;

import com.atguigu.cloud.apis.PayFeignApi;
import com.atguigu.cloud.entities.PayDTO;
import com.atguigu.cloud.resp.ResultData;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ViGrayThorn
 * @since 1.0.0
 * date 2025-09-09 14:42:35
 */
@RestController
@RequestMapping(value = "/consumer/")
@Tag(name = "订单微服务模块(Feign)", description = "基于Feign的订单CRUD操作")
public class OrderController {

	@Resource
	private PayFeignApi payFeignApi;

	@PostMapping(value = "pay/add")
	@Operation(summary = "新增订单", description = "通过Feign客户端调用支付服务新增订单")
	public ResultData<String> addOrder(@RequestBody PayDTO payDTO) {
		return payFeignApi.addPay(payDTO);
	}

	@DeleteMapping(value = "pay/delete/{id}")
	@Operation(summary = "删除订单", description = "通过Feign客户端调用支付服务删除指定ID的订单")
	public ResultData<Integer> deleteOrder(
			@Parameter(description = "订单ID", required = true, example = "1")
			@PathVariable("id") Integer id) {
		return payFeignApi.deletePay(id);
	}

	@PutMapping(value = "pay/update")
	@Operation(summary = "修改订单", description = "通过Feign客户端调用支付服务修改订单信息")
	public ResultData<String> updateOrder(@RequestBody PayDTO payDTO) {
		return payFeignApi.updatePay(payDTO);
	}

	@GetMapping(value = "pay/select/{id}")
	@Operation(summary = "按照ID查订单", description = "通过Feign客户端调用支付服务根据ID查询订单详情")
	public ResultData<PayDTO> selectOrderById(
			@Parameter(description = "订单ID", required = true, example = "1")
			@PathVariable("id") Integer id) {
		return payFeignApi.selectById(id);
	}

	@GetMapping(value = "pay/selectAll")
	@Operation(summary = "查询全部订单", description = "通过Feign客户端调用支付服务查询所有订单列表")
	public ResultData<List<PayDTO>> selectAllOrders() {
		return payFeignApi.selectAll();
	}
}
